<?php
declare (strict_types = 1);

namespace app\validate;

use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'email' => "require|email|unique:user",
        'password' => 'require',
        'salt' => 'require',
        'nickname' => 'require',
        'sex' => 'number|in:0,1,2',
        'phone' => 'number|max:11'
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'email.require' => '邮箱必填',
        'email.email' => '邮箱格式不对',
        'email.unique' => '邮箱已存在，请重新输入',
        'password.require'  => '密码必填',
        'nickname.require'  => '昵称必填',
        'salt.require'      => '密码盐必填',
        'sex.require'    => '性别必填',
        'phone.require' => '手机号必填',
        'phone.max' => '手机号必须11位'
    ];

    /**
     * 定义验证场景
     */
    protected $scene =[
        'register' => ['email','password','salt']
    ];
}
